from runtasks.random_number_main import show    # 导入 show
from runtasks.server import app_run
from concurrent.futures import ThreadPoolExecutor,wait,ALL_COMPLETED
from runtasks.crawler import address_crawler
from runtasks.analysis import analysis
from runtasks.test import test
from runtasks.chatchat import chat_run

# https://www.zhihu.com/question/472482760/answer/2074449915
# ctrl+enter提问的时候会搜索整个项目，Ctrl+l提问AI当前文件，ctrl+k提问AI当前代码块，enter根据问题回答
# 虚拟环境：python -m venv .venv
# 依赖包编码问题解决方案：打开文件，另存为选择ANSI编码，不过编辑器打开会出现乱码
# 安装依赖：pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
def thread_task():
    # 创建线程池
    with ThreadPoolExecutor(max_workers=2) as executor:
        # 提交任务,app_run()在最后执行
        show_future = executor.submit(show)
        address_future = executor.submit(show)
        futures = [show_future,address_future]

        try:
            # result等待任务完成
            # show_future.result()
            wait(futures,return_when=ALL_COMPLETED)
        except Exception as e:
            print(f"KeyboardInterrupt...{e}")
        finally:
            executor.shutdown()
            print("Shutdown complete")

# https://www.zhihu.com/question/472482760/answer/2074449915
# 虚拟环境配置 python -m venv .venv
if __name__ == "__main__":
    # thread_task()
    # address_crawler()
    # analysis()
    # test()
    # app_run()

    # 先运行base_chinese.py生成模型，然后执行命令下载chatglm2-6b-int4模型
    # 下载chatglm2-6b-int4模型命令huggingface-cli download THUDM/chatglm2-6b-int4 --local-dir D:/demo/gitee/python/models/chatglm2-6b-int4 --local-dir-use-symlinks False
    # 然后运行chat_run.py，首次运行会加载model.safetensors文件，需要等待几分钟
    # 如果是cpu模式，需要修改knowledge.py文件，修改embeddings模型
    chat_run()